package com.yanqu.road.server.cmd.activity.suitang.cross;

import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.TongBingProto;
import com.yanqu.road.pb.activity.suitang.SuiTang;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.utils.property.PropertyHelper;
import io.netty.channel.ChannelHandlerContext;


@Cmd(code = GameProtocol.S_CROSS_SUI_TANG_CITY_FOOD_COLLECT, desc = "城池采集一键收获")
public class SuiTangCityFoodCollectCmd implements Command {

    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage packet) throws Exception {
        SuiTang.SuiTangCityFoodCollectRespMsg reqMsg = SuiTang.SuiTangCityFoodCollectRespMsg.parseFrom(packet.getBytes());
        long userId = packet.getPlayerId();
        GamePlayer player = GamePlayerMgr.getOnlinePlayer(userId);
        if(player != null){
            if(reqMsg.getRet() == 0){
                player.getModule(CurrencyModule.class)
                        .addCurrency(PropertyHelper.parseStringToProperty(reqMsg.getReward()),eLogMoneyType.SuiTang,eLogMoneyType.SuiTangCityFoodCollect);
            }
            player.sendPacket(ClientProtocol.U_SUI_TANG_CITY_FOOD_COLLECT, reqMsg.toBuilder());
        }
    }

}
